From b76d5bda37ed8983bc3a43781b32a66c24bb8b9d Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 10 May 2019 17:09:59 +0200 Subject: [PATCH] cssparser: Don't allow commit_token() on block EOF When we're at the end of a block and gtk_css_parser_get_token() returns NULL, gtk_css_parser_commit_token() still consumed the next token. It does not anymore. This does not affect the CSS parser, but it exposes issues with the render parser, which previously just consumed too many closing } tokens in the past. --- gtk/css/gtkcssparser.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/gtk/css/gtkcssparser.c b/gtk/css/gtkcssparser.c index 2ead2e09af..5ba0997b4d 100644 --- a/gtk/css/gtkcssparser.c +++ b/gtk/css/gtkcssparser.c @@ -335,7 +335,9 @@ gtk_css_parser_consume_token (GtkCssParser *self) /* unpreserved tokens MUST be consumed via start_block() */ g_assert (gtk_css_token_is_preserved (&self->token, NULL)); - gtk_css_token_clear (&self->token); + /* Don't consume any tokens at the end of a block */ + if (!gtk_css_token_is (gtk_css_parser_peek_token (self), GTK_CSS_TOKEN_EOF)) + gtk_css_token_clear (&self->token); } void @@ -435,7 +437,15 @@ gtk_css_parser_end_block (GtkCssParser *self) else { g_array_set_size (self->blocks, self->blocks->len - 1); - gtk_css_parser_skip (self); + if (gtk_css_token_is_preserved (&self->token, NULL)) + { + gtk_css_token_clear (&self->token); + } + else + { + gtk_css_parser_start_block (self); + gtk_css_parser_end_block (self); + } } } -- 2.30.2